fix: ApplicationImpl.Begin raises SessionBegun after state changes (#5162)#5184
fix: ApplicationImpl.Begin raises SessionBegun after state changes (#5162)#5184
Conversation
…5162) Per the Cancellable Workflow Pattern (CWP), state mutations must complete before notifications. ApplicationImpl.Begin was invoking SessionBegun inside the session-stack lock and BEFORE calling SetIsRunning(true) and SetIsModal(true) on the runnable, so subscribers observed a SessionToken whose Runnable.IsRunning and IsModal were still false. Move the SetIsRunning/SetIsModal calls ahead of SessionBegun (still inside the lock), and raise SessionBegun outside the lock after all state has been committed. This matches the symmetric End()/SessionEnded pattern. https://claude.ai/code/session_01CdoS4YQ7v9aNPZaNsYnxjv
|
Closing this PR — on reflection the issue framing was wrong.
The original placement before Closing #5184 unmerged. Issue #5162 is being closed wontfix in favor of a small doc-only PR that tightens the XML on Generated by Claude Code |
#5162 closed not_planned and PR #5184 closed unmerged after the CWP framing was found to overstate the contract: SessionBegun is a token-creation hook, SessionEnded is a token-disposal hook, and they are deliberately not symmetric with the IsRunningChanged state-change events. Replaced by doc-only PR #5188 tightening XML on IApplication.cs. https://claude.ai/code/session_01CdoS4YQ7v9aNPZaNsYnxjv
Fixes #5162.
Summary
ApplicationImpl.Beginviolated the Cancellable Workflow Pattern (CWP): it invoked theSessionBegunevent inside the session-stack lock and before callingSetIsRunning(true)/SetIsModal(true)on the runnable. Subscribers observed aSessionTokenwhoseRunnable.IsRunningandIsModalwere stillfalse.SetIsRunning(true),SetIsModal(true),previousTop?.SetIsModal(false)) inside the lock, and raiseSessionBegunafter the lock is released. This mirrors the existing symmetricEnd()/SessionEndedpattern.Tests/UnitTests.NonParallelizablethat subscribes toSessionBegunand assertsIsRunning == trueandIsModal == trueon the event'sSessionToken.Runnable.The test was empirically verified to FAIL on
develop(with the original ordering) and PASS after the fix. All 14 existingBeginEndtests and the broaderApplicationTestssuite (548 tests) continue to pass.Test plan
SessionBegunCwpTests.SessionBegun_Raised_After_IsRunning_And_IsModal_Set_Truefails on unfixed code (observedIsRunning == false)dotnet buildsucceedsBeginEndTests(14 tests) passApplicationTestsnamespace inUnitTestsParallelizablepasses (548/548 + 2 pre-existing skips)https://claude.ai/code/session_01CdoS4YQ7v9aNPZaNsYnxjv
Generated by Claude Code